package com.dc.designPattern._5_adapter._2_objectAdapter;

import java.util.Objects;

/**
 * Description: 对象适配器_适配器类
 * @author: gdc
 * @date: 2021/3/10
 * @version 1.0
 */
public class VoltageAdapter implements IVoltage5V {

    /**
     * 目标对象，聚合关系
     */
    private Voltage220V voltage220V;

    /**
     * 通过构造器引入目标对象
     * @param voltage220V           目标对象
     */
    public VoltageAdapter(Voltage220V voltage220V) {
        this.voltage220V = voltage220V;
    }

    @Override
    public int output5V() {
        if (Objects.isNull(voltage220V)) {
            return 0;
        }

        // 获取原始电压
        int originVoltage = voltage220V.output220V();
        // 通过复杂的业务逻辑转换为 5V
        int targetVoltage = originVoltage / 44;
        return targetVoltage;
    }
}
